package com.base.cn.platform.os.entity.course.note;

import com.base.cn.platform.os.common.annotation.ImgAttr;
import com.base.cn.platform.os.common.mybatis.BaseEntity;
import com.base.cn.platform.os.entity.course.catalog.CourseCatalog;
import com.base.cn.platform.os.entity.course.cou.Course;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.util.Map;
import java.util.Objects;

/**
 * 课程笔记
 *
 * @author SK
 * @since 2018-06-19
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class CourseNote extends BaseEntity {
    //购买课程的ID
    private BigDecimal buyCourseId;
    //课程ID
    private BigDecimal courseId;
    //目录ID
    private BigDecimal catalogId;
    //用户ID
    private BigDecimal userId;
    //用户播放进度（单位/秒）
    private Integer progress;
    //笔记内容
    @ImgAttr
    private String note;
    //用户对象
    private Map<String, Object> user;
    //笔记的课程
    private Course course;
    //目录对象
    private CourseCatalog catalog;
    private String describe;

    public void description(CourseCatalog parent) {
        this.describe = "";
        if (parent != null) {
            this.describe += parent.getCatalogName() + " > ";
        }
        this.describe += catalog.getCatalogName() + " ";
        this.describe += longTimeToString();
    }

    private String longTimeToString() {
      if (Objects.isNull(progress)) {
          return "00:00";
      }
      int hours = this.progress / 3600;
      int minutes = this.progress % 3600 / 60;
      int seconds = this.progress % 3600 % 60;
      String time = "" + seconds;
      time = (minutes > 9 ? minutes : "0" + minutes) + ":" + time;
      time = (hours > 0 ? hours + ":" : "") + time;
      return time;
    }
}
